import axios from 'axios';
import Config from 'react-native-config';

const baseHttp = axios.create({
  baseURL: Config.MOCK_URL,
  // 当前请求为跨域类型时是否在请求中协带cookie
  withCredentials: true,
  timeout: 10000,
});

// 请求拦截
baseHttp.interceptors.request.use(
  config => {
    return config;
  },
  err => {
    return Promise.reject(err);
  },
);

// 响应拦截
baseHttp.interceptors.response.use(
  response => {
    return response.data;
  },
  err => {
    return Promise.reject(err);
  },
);

export default baseHttp;
